# There are 6 study conditions: A B C D E F. These match the csv files. C1 D1 E1
# F1 CSV files are subsets of the files mentioned above, with fewer studies. We
# can't find an explanation in text for this subsetting strategy. The results
# with superset files match Table 2 from the paper, which seem to be the main
# results.

source(here::here("code/load.R"))

files <- paste0(here("data/meta_analyses_raw/ZhaEtAl2021/"),
                list.files(here("data/meta_analyses_raw/ZhaEtAl2021/"), pattern = "[A-Z].csv"))

read_dir <- function(file_name) {
  read_csv(file_name) |>
    mutate(meta_id = "ZhaEtAl2021",
           question = "Does the expectancy-disconfirmation model explain citizen satisfaction with public services?",
           dv = `Which part of the model is being tested?`,
           dv = case_when(startsWith(dv, "A") ~ "A",
                          startsWith(dv, "B") ~ "B",
                          startsWith(dv, "C") ~ "C",
                          startsWith(dv, "D") ~ "D",
                          startsWith(dv, "E") ~ "E",
                          startsWith(dv, "F") ~ "F"),
           subfield = "PA",
           study_id = paste(Author, Journal, sep = ", "),
           overall_effect = "no") |>
    select(meta_id,
           subfield,
           study_id,
           study_year = Year,
           question,
           dv,
           estimate = TE,
           std.error = seTE,
           sample_size = sample,
           overall_effect)
}

files |>
  map_df(~ read_dir(.)) |>
  write_csv(here("data/meta_analyses_clean/ZhaEtAl2021.csv"))

